<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>watch监听器的使用</title>
    <script src="./lib/vue-2.4.0.js"></script>
</head>
<body>
    <div id="app">
        姓:<input type="text" placeholder="firstName" v-model='firstName'>
        名:<input type="text" placeholder="lastName" v-model='lastName'>
        <p>全名:{{fullName}}</p>
    </div>
</body>
<script>
    var vm=new Vue({
        el:'#app',
        data:{
            firstName:'',
            lastName:'',
            fullName:''
        },
        methods:{
        },
        //监听data里已经定义过的属性:此种监听方式对对象无效
        watch:{
            firstName(newVal,oldVal){
                this.fullName=newVal+this.lastName;
            },
            lastName(newVal,oldVal){
                this.fullName=this.firstName+newVal;
            }
        }
    });
</script>
</html>